package com.zz.cc.owner.app;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zz.cc.owner.R;
import com.zz.cc.owner.TitleBaseActivity;
import com.zz.common.widget.ZListView;

public class OtherActivity extends TitleBaseActivity implements OnItemClickListener {

	private ZListView mListView;
	private OtherAdapter mAdapter;
	private final List<Integer> mServices = new ArrayList<Integer>();
	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_other);
		initUI();
		fillView();
		refresh();
	}
	
	private void initUI() {
		mListView = (ZListView) findViewById(R.id.other_list_view);
	}
	
	private void fillView() {
		setCurrentTitle(R.string.other_title);
		mAdapter = new OtherAdapter();
		mListView.setAdapter(mAdapter);
	}
	

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		//TODO
		
	}
	
	private void refresh() {
		mServices.clear();
		mServices.add(Integer.valueOf(R.string.other_modify_basic_info));
		mServices.add(Integer.valueOf(R.string.other_account));
		mServices.add(Integer.valueOf(R.string.other_upgrade));
		mServices.add(Integer.valueOf(R.string.other_contact_us));
		mServices.add(Integer.valueOf(R.string.other_help));
		mServices.add(Integer.valueOf(R.string.other_about));
		
		mAdapter.notifyDataSetChanged();
	}
	
	private static class ViewHolder {
		public TextView mTvTitle;
		public int mTitleId;
	}
	
	private class OtherAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return mServices.size();
		}

		@Override
		public Object getItem(int position) {
			return mServices.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if(null == convertView) {
				convertView = LayoutInflater.from(OtherActivity.this).inflate(R.layout.list_item_other, null);
				holder = new ViewHolder();
				holder.mTvTitle = (TextView) convertView.findViewById(R.id.other_list_item_title);
				
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.mTitleId = mServices.get(position);
			holder.mTvTitle.setText(holder.mTitleId);
			return convertView;
		}
		
	}

	

}
